home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / sim / z8k / iface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  2.9 KB  |  161 lines

  1. /* gdb->simulator interface.
  2.    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of Z8KSIM
  5.  
  6. Z8KSIM is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Z8KSIM is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Z8KSIM; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <ansidecl.h>
  21. #include "sim.h"
  22. #include "tm.h"
  23. #include "signal.h"
  24. #include "remote-sim.h"
  25.  
  26. int
  27. sim_clear_breakpoints ()
  28. {
  29.   return 1;
  30. }
  31.  
  32. int
  33. sim_set_pc (addr)
  34.      SIM_ADDR addr;
  35. {
  36.   tm_store_register (REG_PC, addr);
  37.   return 0;
  38. }
  39.  
  40. int
  41. sim_store_register (regno, value)
  42.      int regno;
  43.      unsigned char *value;
  44. {
  45.   /* FIXME: Review the computation of regval.  */
  46.   int regval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
  47.  
  48.   tm_store_register (regno, regval);
  49.   return 0;
  50. }
  51.  
  52. int
  53. sim_fetch_register (regno, buf)
  54.      int regno;
  55.      unsigned char *buf;
  56. {
  57.   tm_fetch_register (regno, buf);
  58.   return 0;
  59. }
  60.  
  61. int
  62. sim_write (where, what, howmuch)
  63.      SIM_ADDR where;
  64.      unsigned char *what;
  65.      int howmuch;
  66. {
  67.   int i;
  68.  
  69.   for (i = 0; i < howmuch; i++)
  70.     tm_write_byte (where + i, what[i]);
  71.   return howmuch;
  72. }
  73.  
  74. int
  75. sim_read (where, what, howmuch)
  76.      SIM_ADDR where;
  77.      unsigned char *what;
  78.      int howmuch;
  79. {
  80.   int i;
  81.  
  82.   for (i = 0; i < howmuch; i++)
  83.     what[i] = tm_read_byte (where + i);
  84.   return howmuch;
  85. }
  86.  
  87. static
  88. void 
  89. control_c (sig, code, scp, addr)
  90.      int sig;
  91.      int code;
  92.      char *scp;
  93.      char *addr;
  94. {
  95.   tm_exception (SIM_INTERRUPT);
  96. }
  97.  
  98. int
  99. sim_resume (step, sig)
  100.      int step;
  101.      int sig;
  102. {
  103.   void (*prev) ();
  104.  
  105.   prev = signal (SIGINT, control_c);
  106.   tm_resume (step);
  107.   signal (SIGINT, prev);
  108.   return 0;
  109. }
  110.  
  111. int
  112. sim_stop_reason (reason, sigrc)
  113.      enum sim_stop *reason;
  114.      int *sigrc;
  115. {
  116.   switch (tm_signal ())
  117.     {
  118.     case SIM_DIV_ZERO:
  119.       *sigrc = SIGFPE;
  120.       break;
  121.     case SIM_INTERRUPT:
  122.       *sigrc = SIGINT;
  123.       break;
  124.     case SIM_BAD_INST:
  125.       *sigrc = SIGILL;
  126.       break;
  127.     case SIM_BREAKPOINT:
  128.       *sigrc = SIGTRAP;
  129.       break;
  130.     case SIM_SINGLE_STEP:
  131.       *sigrc = SIGTRAP;
  132.       break;
  133.     case SIM_BAD_SYSCALL:
  134.       *sigrc = SIGSYS;
  135.       break;
  136.     case SIM_BAD_ALIGN:
  137.       *sigrc = SIGSEGV;
  138.       break;
  139.     case SIM_DONE:
  140.       *sigrc = 1;
  141.       *reason = sim_exited;
  142.       return 0;
  143.     default:
  144.       abort ();
  145.     }
  146.   *reason = sim_stopped;
  147.   return 0;
  148. }
  149.  
  150. int
  151. sim_info (printf_fn, verbose)
  152.      void (*printf_fn)();
  153.      int verbose;
  154. {
  155.   sim_state_type x;
  156.  
  157.   tm_state (&x);
  158.   tm_info_print (&x);
  159.   return 0;
  160. }
  161.